package com.itheima.appserver.config;

import com.itheima.appserver.interceptor.CacheInterceptor;
import com.itheima.appserver.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类
 * 有多个拦截器时注意拦截器的顺序
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    TokenInterceptor tokenInterceptor;

    @Autowired
    CacheInterceptor cacheInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 处理Token的拦截器
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**");
        registry.addInterceptor(cacheInterceptor).addPathPatterns("/**");
    }
}
